/**
 * [OElove] (C)2010-2099 OELOVE.COM Inc. X
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 * $ Last update 2017/03/31 by CL $
*/
$(function(){ 
	
	//打开编辑用户名页面
	$("[f='but_open_edit_item']").bind("click", function(){
		$_mod = $(this).attr("data-mod");
		//$_html = $("#edit_"+$_mod).html();
		//oeShadeBox("myedit", "html", $_html, 500, 180);
		$_url = _OE_FILE + "&c=profile&a=edititem&mod="+$_mod;
		oeShadeBox("myedit", "ajax", $_url, 500, 180);
	});


	//保存修改 用户名、姓名、生日
	$(document).on("click", "[f='but_save_edit_item']", function(){
		$_mod = $(this).attr("data-mod");
		$url = _OE_FILE + "&c=profile";
		$text_tips = "";
		if ($_mod == "username") {
			$username = $("#username").val();
			if ($username.length == 0) {
				ToastShow("请填写3-16个字符的用户名");
				return false;
			}
			$url = $url+"&a=editname&username="+$username;
			$text_tips = $username;
		}
		else if ($_mod == "gender") {
			$gender = $("#gender").val();
			if ($gender.length == 0) {
				ToastShow("请选择性别");
				return false;
			}
			$url = $url+"&a=editgender&gender="+$gender;
			if ($gender == 1) {
				$text_tips = "男";
			}
			else {
				$text_tips = "女";
			}
		}
		else if ($_mod == "age") {
			$ageyear = $("#ageyear").val();
			$agemonth = $("#agemonth").val();
			$ageday = $("#ageday").val();
			if ($ageyear.length == 0) {
				ToastShow("请选择年份");
				return false;
			}
			if ($agemonth.length == 0) {
				ToastShow("请选择月份");
				return false;
			}
			if ($ageday.length == 0) {
				ToastShow("请选择日期");
				return false;
			}
			$url = $url+"&a=editage&ageyear="+$ageyear+"&agemonth="+$agemonth+"&ageday="+$ageday;
			$text_tips = $ageyear+"-"+$agemonth+"-"+$ageday;
		}
		$.ajax({
			type: "POST",
			url: $url,
			cache: false,
			data: {datatype:"json", r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					if ($_mod == "username") {
						$("#li_username").find("label").html($text_tips);
						$("#li_username").find("i").remove();
					}
					else if ($_mod == "gender") {
						$("#li_gender").find("label").html($text_tips);
						$("#li_gender").find("i").remove();
					}
					else if ($_mod == "age") {
						$("#li_age").find("label").html($text_tips);
						$("#li_age").find("i").remove();
					}
					_closeShadeBox("myedit");
					ToastShow("修改成功");
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("修改失败，请检查！");
					}
				}
			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});

	});


	//帮我写
	$(document).on("click", "[f='but_helpme_write']", function(){
		$.ajax({
			type: "POST",
			url: _OE_FILE + "&c=profile",
			cache: false,
			data: {a:"helpmewrite", datatype:"json", r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					$("#monolog_content").val($result);
					_countTextSize("monolog_content", "tips_num"); //统计字数
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("获取数据失败");
					}
				}
			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});
	});

	

});

